﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TestOnlineProject.Models.Entities
{
    public class DownloadModel: ActionResult
    {
        public DownloadModel()
        {
            
        }
        public DownloadModel(string virtualPath)
        {
            this.VirtualPath = virtualPath;
        }

        public string VirtualPath { get; set; }
        public string FileDownLoadName { get; set; }

        public override void ExecuteResult(ControllerContext context)
        {
            if(!String.IsNullOrEmpty(FileDownLoadName))
            {
                context.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" + this.FileDownLoadName);
            }
            string filePath = context.HttpContext.Server.MapPath(this.VirtualPath);
            context.HttpContext.Response.TransmitFile(filePath);
        }
    }
}